package com.makeunion.gdlbsdemo.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdate;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.LatLngBounds;
import com.makeunion.gdlbsdemo.R;

/**
 * 类说明
 *
 * @author renjialiang
 * @version [版本]
 * @see [相关类]
 * @since [模块]
 */
public class ControlApiActivity extends AppCompatActivity {

    private MapView mapView;

    private AMap aMap;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_control_api);

        mapView = (MapView) findViewById(R.id.map_view);
        mapView.onCreate(savedInstanceState); //此方法必须重写
        init();
    }

    private void init() {
        if (aMap == null) {
            aMap = mapView.getMap();
        }
        aMap.showIndoorMap(true);
    }

    public void animMove(View view) {
        aMap.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(
                        new LatLng(39.92463, 116.389139), //经纬度
                        16, //缩放级别 3 -19 3：最大视角，看到全中国，19：最小级别，看到细节
                        60, //视角从垂直于地面，向下倾斜60度，此时与地面夹角是30度
                        90) //地图顺时针旋转90度
                ),
                1500,
                new AMap.CancelableCallback() {
                    @Override
                    public void onFinish() {}

                    @Override
                    public void onCancel() {}
                });
    }

    public void noAnimMove(View view) {
        aMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(
                new LatLng(39.92463, 116.389139), //经纬度
                16, //缩放级别 3 -19 3：最大视角，看到全中国，19：最小级别，看到细节
                60, //视角从垂直于地面，向下倾斜60度，此时与地面夹角是30度
                90) //地图顺时针旋转90度
        ));
    }

    public void moveMapCenter(View view) {
        CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(
                new CameraPosition(new LatLng(39.977290,116.337000), 16, 0, 0));
        aMap.moveCamera(cameraUpdate);
    }

    public void zoomIn(View view) {
        aMap.moveCamera(CameraUpdateFactory.zoomIn());
    }

    public void zoomOut(View view) {
        aMap.moveCamera(CameraUpdateFactory.zoomOut());
    }

    public void limitArea(View view) {
        LatLng southwestLatLng = new LatLng(34, 105);
        LatLng northeastLatLng = new LatLng(38, 115);
        LatLngBounds latLngBounds = new LatLngBounds(southwestLatLng, northeastLatLng);
        aMap.setMapStatusLimits(latLngBounds);
    }

    public void defaultArea(View view) {
        Toast.makeText(this, "暂不演示", Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mapView.onResume();
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onPause() {
        super.onPause();
        mapView.onPause();
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
    }
}
